#tag Class
Protected Class SlotGrid
	#tag Method, Flags = &h21
		Private Sub Constructor(northWest as boolean, north as boolean, northEast as boolean, west as boolean, center as boolean, east as boolean, southWest as boolean, south as boolean, southEast as boolean)
		  //deprecated
		  'slotDictionary = new Dictionary
		  '
		  'if northWest = true then
		  'slotDictionary.Value("nw") = new Slot
		  'end if
		  '
		  'if north = true then
		  'slotDictionary.Value("n") = new Slot
		  'end if
		  '
		  'if northEast = true then
		  'slotDictionary.Value("ne") = new Slot
		  'end if
		  '
		  'if west = true then
		  'slotDictionary.Value("w") = new Slot
		  'end if
		  '
		  'if center = true then
		  'slotDictionary.Value("c") = new Slot
		  'end if
		  '
		  'if east = true then
		  'slotDictionary.Value("e") = new Slot
		  'end if
		  '
		  'if southWest = true then
		  'slotDictionary.Value("sw") = new Slot
		  'end if
		  '
		  'if south = true then
		  'slotDictionary.Value("s") = new Slot
		  'end if
		  '
		  'if southEast = true then
		  'slotDictionary.Value("se") = new Slot
		  'end if
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function CenterSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("c")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function EastSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("e")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function NorthSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("n")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function NorthEastSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("ne")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function NorthWestSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("nw")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function WestSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("w")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function SouthWestSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("sw")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function SouthSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("s")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function SouthEastSlotIsValid() As boolean
		  //deprecated
		  return slotDictionary.HasKey("se")
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Constructor(tile as Tile)
		  baseTile = tile
		  slotDictionary = new Dictionary
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub SetSlot(pos as String, type as integer)
		  if baseTile.rotated = false then
		    slotDictionary.Value(pos) = new Slot(type, self, baseTile, pos)
		  else
		    app.RaiseError(202, "Setting a new slot on a rotated tile!", "Gamepiece.Settype", 3)
		  end if
		  
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetSlot(pos as string) As slot
		  //returns either a valid slot at position or, if not found
		  //a new slot that has active-property set to false
		  
		  return slotDictionary.Lookup(pos, new Slot(false))
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Function GetAllSlots() As Dictionary
		  return slotDictionary
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetOwner() As game.Player
		  //returns the owner of an occupied slot or nil if there is no owner
		  
		  dim slots() as Variant
		  dim keys() as variant
		  dim theSlot as board.Slot
		  dim i as integer
		  dim thePlayer as game.Player
		  
		  slots = slotDictionary.Values
		  
		  
		  for i = 0 to ubound (slots)
		    if slots(i).ObjectValue IsA board.Slot then
		      theSlot = board.Slot(slots(i))
		      if theSlot.occupied = true then
		        return theSlot.occupier.getPlayer
		        exit for
		      end if
		    end if
		  next i
		  
		  return nil
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetIsOccupied() As boolean
		  dim slots() as Variant
		  dim theSlot as board.Slot
		  dim i as integer
		  
		  slots = slotDictionary.Values
		  
		  
		  for i = 0 to ubound (slots)
		    if slots(i).ObjectValue IsA board.Slot then
		      theSlot = board.Slot(slots(i))
		      if theSlot.occupied = true then
		        return true
		        exit for
		      end if
		    end if
		  next i
		  
		  return false
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub FreeSlots()
		  dim slots() as Variant
		  dim theSlot as board.Slot
		  dim i as integer
		  
		  slots = slotDictionary.Values
		  
		  
		  for i = 0 to ubound (slots)
		    if slots(i).ObjectValue IsA board.Slot then
		      theSlot = board.Slot(slots(i))
		      if theSlot.occupied = true then
		        call theSlot.RemoveGamepiece
		        exit for
		      end if
		    end if
		  next i
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetOccupiedType() As string
		  //returns the Type of field (town, street, grassland, monastrery if a slot is occupied,
		  //otherwise returns "undefined"
		  
		  dim slots() as Variant
		  dim theSlot as board.Slot
		  dim i as integer
		  
		  slots = slotDictionary.Values
		  
		  
		  for i = 0 to ubound (slots)
		    if slots(i).ObjectValue IsA board.Slot then
		      theSlot = board.Slot(slots(i))
		      if theSlot.occupied = true then
		        return theSlot.GetType
		        exit for
		      end if
		    end if
		  next i
		  
		  return "undefined"
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetPossibleSlots() As slot()
		  dim slots() as slot
		  dim varSlots() as variant
		  dim theSlot as board.slot
		  dim i as integer
		  
		  if GetIsOccupied = false then
		    varSlots = slotDictionary.Values
		    for i = 0 to ubound (varSlots)
		      if varslots(i) isa board.Slot then
		        theSlot = board.Slot(varSlots(i))
		        if theSlot.isActive = true then
		          slots.Append theSlot
		        end if
		        'slot.Append board.Slot(varSlots(i))
		      end if
		    next
		  end if
		  
		  '
		  'for i = 0 to ubound(slots)
		  'if slots(i).IsActive = false then
		  'MsgBox "wrong"
		  'end if
		  'next
		  
		  return slots
		End Function
	#tag EndMethod


	#tag Property, Flags = &h21
		Private slotDictionary As Dictionary
	#tag EndProperty

	#tag Property, Flags = &h21
		Private baseTile As Tile
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
